import compose from "koa-compose";
import compress from "koa-compress";
import cors from "koa2-cors";
import logger from "koa-logger";
import bodyParser from "koa-bodyparser";
import staticPath from "./koa-static.js";
import koajsJwt from "koa-jwt";
import { jwtConfig, whitePathList  } from "../database/config.js";
import checkExpiredToken from "./koa-checkExpiredToken.js";
const { secret} = jwtConfig;

const list = [
    logger(),
    compress(),
    bodyParser(),
    staticPath(),
    koajsJwt({ secret }).unless({ path: whitePathList }),
    checkExpiredToken,
    cors({ origin: '*', credentials: true }), // 必须放在最后才能确保生效, 因为 koa-jwt 会刷新 cors 配置
]
const middlewares = compose(list);

export default middlewares;
